package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.dto.GoodsSalesDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.entity.Orders;
import com.sky.vo.OrderPageVo;
import com.sky.vo.OrderVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.List;

/**
 * @author 赵星
 * @version 1.0
 * @Date 2023/9/27 21:08
 */
@Mapper
public interface OrderMapper {
    void insert(Orders orders);
    /**
     * 根据订单号查询订单
     * @param orderNumber
     */
    @Select("select * from orders where number = #{orderNumber}")
    Orders getByNumber(String orderNumber);

    /**
     * 修改订单信息
     * @param orders
     */
    void  update(Orders orders);

    //根据用户id查询订单
    Page<OrderPageVo> pageQuery(Long userId,Integer status);

    //根据订单id查询订单
    @Select("select * from orders where id = #{id}")
    OrderPageVo selectOrderById(Long id);

    @Update("update orders set status = 6 where id = #{id}")
    void cancel(Integer id);

    //分页搜素订单
    Page<OrderVO> conditionSearch(OrdersPageQueryDTO ordersPageQueryDTO);

    @Select("select count(*) from orders where status = #{status}")
    Integer selectStatistics(Integer status);

    //定时查询
    @Select("select * from orders where status = #{status} and order_time < #{time}")
    List<Orders> getStatusAndOrderTime(Integer status, LocalDateTime time);

    Double sumAmountByMap(HashMap<String, Object> map);

    Integer countAllByMap(HashMap<String, Object> map);

    List<GoodsSalesDTO> getDishNameByMap(HashMap<String, Object> map);
}
